package org.tinygroup.cepcore.test;

import org.tinygroup.cepcore.CEPCore;
import org.tinygroup.cepcore.CEPCoreProcessFilter;
import org.tinygroup.cepcore.EventProcessor;
import org.tinygroup.event.Event;
import org.tinygroup.logger.Logger;
import org.tinygroup.logger.LoggerFactory;

public class ProcessTestFilter implements CEPCoreProcessFilter {
	private CEPCoreProcessFilter nextFilter;
	private final static Logger LOGGER = LoggerFactory.getLogger(ProcessTestFilter.class);
	private String index = "";

	public ProcessTestFilter(String index) {
		super();
		this.index = index;
		
	}

	public void setNext(CEPCoreProcessFilter filter) {
		this.nextFilter = filter;
	}

	public CEPCoreProcessFilter getNext() {
		return nextFilter;
	}

	public void process(Event e, CEPCore core, EventProcessor processor) {
		LOGGER.infoMessage("=============={}===============", index);
		addValue(index);
		if (getNext() != null){
			getNext().process(e, core, processor);
		}
			

	}

	private static String value = "";

	private void addValue(String index) {
		value = value + index;
	}

	public static String getValue() {
		String result = value;
		value = "";
		return result;
	}

	@Override
	public int compareTo(CEPCoreProcessFilter o) {
		return getId().compareTo(o.getId());
	}

	@Override
	public String getId() {
		return index;
	}
	
}
